﻿using gt.UserInfo.DomainModels.Respository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace gt.UserInfo.Intrastructures.EF
{
    //EF事务处理三种方式，saveChanges,transation,scopetrasation。这里简单处理
    //核心思路 保证 UnitOfWork和Repository 的引用DBContext一致！！
    public class EFUnitOfWork<TDBContext> : IUnitOfWork where TDBContext : DbContext
    {
        private readonly TDBContext _dbContext;

        public EFUnitOfWork(TDBContext dBContext)
        {
            _dbContext = dBContext ?? throw new ArgumentNullException(nameof(dBContext));
        }

        public int SaveChanges()
        {
            return _dbContext.SaveChanges();
        }
    }
}
